package cn.edu.scau.sec.rw.model.pro_manage;

import cn.edu.scau.sec.rw.model.pro_manage.simulation.Register;

import java.util.ArrayList;
import java.util.List;

/**
 * 进程控制块PCB
 */
public class PCB {

    private static List<Integer> id = new ArrayList<Integer>();
    private static List<PCB> pcbList = new ArrayList<PCB>();
    private static final int pcbCount = 10;

    private Integer proId;
    private Register register = new Register();
    private String proState = "空白";
    private String blockReason;

    public int ifIO;
    public int StartIO, EndIO;

    /**
     * 设置可分配的进程控制块号
     */
    static {
        for(int i = 0; i < 10; i++) {
            id.add(i);
        }
    }

    private PCB() {
    }

    /**
     * 采用多例模式，设置进程控制块可分配数量
     * @return
     */
    public static PCB getPCB() {

        PCB onePCB = null;
        if (pcbList.size() < pcbCount) {
            onePCB = new PCB();
            onePCB.setProId(id.get(0));
            id.remove(0);
            pcbList.add(onePCB);
        }
        return onePCB;
    }

    public List<Integer> getId() {
        return id;
    }

    public void setId(List<Integer> id) {
        PCB.id = id;
    }

    public List<PCB> getPcbList() {
        return pcbList;
    }

    public void setPcbList(List<PCB> pcbList) {
        PCB.pcbList = pcbList;
    }

    public Integer getProId() {
        return proId;
    }

    public void setProId(Integer proId) {
        this.proId = proId;
    }

    public Register getRegister() {
        return register;
    }

    public void setRegister(Register register) {
        this.register = register;
    }

    public String getProState() {
        return proState;
    }

    public void setProState(String proState) {
        this.proState = proState;
    }

    public String getBlockReason() {
        return blockReason;
    }

    public void setBlockReason(String blockReason) {
        this.blockReason = blockReason;
    }
}
